<?php
include_once("./_common.php");

// 회원 정보 
// $to_ar[0] = youpjung(mb_id)\t정엽(이름)\twjddung@naver(아이디)\t19820430 
$to_ar = explode(',', $to_value);
$w = $_GET['w'];
// 이벤트 g4_write_event wr_id
$event_id = $subj;
//쿠폰 아이디 
//echo $cu_no;
$sql = "";
$mb_id="";
$mb_email = "";
$mb_birth = "";
$mb_name = "";
if($w == "") {
	for($i=0; $i<count($to_ar); $i++){
		$mb_list=$to_ar[$i];
		
		$_mb_id = explode("\t", $mb_list);
		$mb_id = $_mb_id[0];
		$mb_name = $_mb_id[1];
		$mb_email = $_mb_id[2];
		$mb_birth = $_mb_id[3];
		
		$str = 	"mb_id ='$mb_id',
					mb_email = '$mb_email',
					mb_name = '$mb_name',
					mb_birth = '$mb_birth',
					event_id = $event_id,
					cu_no = $cu_no";
							
		$sql = " INSERT INTO coupon_win SET $str ";			
		$rst = sql_query($sql);
		
	}
	
	
}

if($w=="u"){
// 저장된 쿠폰 별 정보를 삭제 후 저장한다.
$sql_del = " DELETE FROM coupon_win WHERE cu_no = $cu_no ";
$rst = sql_query($sql_del);

	for($i=0; $i<count($to_ar); $i++){
		$mb_list=$to_ar[$i];
		
		$_mb_id = explode("\t", $mb_list);
		$mb_id = $_mb_id[0];
		$mb_name = $_mb_id[1];
		$mb_email = $_mb_id[2];
		$mb_birth = $_mb_id[3];
		
		$str = 	"mb_id ='$mb_id',
					mb_email = '$mb_email',
					mb_name = '$mb_name',
					mb_birth = '$mb_birth',
					event_id = $event_id,
					cu_no = $cu_no";
							
		$sql_up = " INSERT INTO coupon_win SET $str ";			
		$rst = sql_query($sql_up);
			
	}
	
}

if($w == "") {
	alert("등록되었습니다.", "./coupon_list.php?bo_table=coupon");
} else if ($w == "u") {
	alert("수정되었습니다.", "./coupon_list.php?bo_table=coupon");
} 

?>
